﻿using System;
using System.Collections.Generic;
using System.Web;
using UniversityManagementSystem.DAL;
using UniversityManagementSystem.Gateway;

namespace UniversityManagementSystem.Manager
{
    [Serializable]
    public class DepartmentManager
    {
        DepartmentGateway gateway = new DepartmentGateway();
        public string SaveNewDepartment(Department department)
        {
            string saveDepartmentMessage = "";
            try
            {
                
                if ((IsNullOrBlank(department.DepartmentCode)) || (IsNullOrBlank(department.DepartmentName)))
                {
                    saveDepartmentMessage = "Please fill up the fields correctly";
                }
                else if(gateway.CheckDepartment(department))
                {
                    saveDepartmentMessage = "Department already exists,Please try another one.";
                }
                else
                {
                    saveDepartmentMessage = gateway.SaveNewDepartment(department);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("An internal error occured,Please try again later.",ex);
            }
            
            return saveDepartmentMessage;
        }
        public bool IsNullOrBlank(String text)
        {
            return text == null || text.Trim().Length == 0;
        }

        public List<Department> GetAllDepartment()
        {
            return gateway.GetAllDepartments();
        }

        public List<string> GetAllBuildings()
        {
            return gateway.GetAllBuildings();
        }

        public List<string> GetAllRooms(string buildingName)
        {
            return gateway.GetAllRooms(buildingName);
        }
    }
}